package edu.info.manager.dao;

import edu.info.manager.domain.StudentJavaBean;
import edu.info.manager.service.StudentService;

public class StudentDao {
   private  static StudentJavaBean Stus[] = new StudentJavaBean[5];

    public  boolean UpdateStudent(String updateid, StudentJavaBean newstu) {
        int index = GetIndex(updateid);
        Stus[index]=newstu;
        return true;
    }


    public boolean addstudent(StudentJavaBean stu) {
        
        int index = -1;
        for (int i = 0; i < Stus.length; i++) {
            StudentJavaBean student = Stus[i];
            if (student == null) {
                index = i;
                break;
            }
        }
        if (index == -1) {
            return false;
        } else {
            Stus[index] = stu;
            return true;
        }
    }

    public static StudentJavaBean[] FindId() {
        return Stus;
    }

    public boolean DeleteStudent(String delnum) {
        int index = GetIndex(delnum);
        Stus[index]=null;
        return true;
    }
    public  int GetIndex(String id)
    {
        int index=-1;
       for (int i = 0; i <Stus.length ; i++) {
            StudentJavaBean student = Stus[i];
            if(student!=null&&student.getId().equals(id))
            {
                index=i;
                break;
            }
        }
        return index;
    }

}

